extends Area2D
class_name PieceV2

# 棋子属性
var type: BoardCommon.TYPE
var side: BoardCommon.TURN
var price: int
@onready var label: Label = $Label
@onready var select_highlight = $SelectHighlight
@onready var collision_shape = $CollisionShape2D

signal click_piece_signal

func _ready() -> void:
	position.x += BoardCommon.offset.x
	position.y += BoardCommon.offset.y
	price = BoardCommon.PIECE_VALUES[type] # 初始化棋子价值
	_update_piece_hightlinght(true)

## 更新棋子高亮状态 参数： 是否是默认 默认参数：false
func _update_piece_hightlinght(is_defalut:bool=false) -> void:
	if select_highlight and select_highlight.material:
		if is_defalut: select_highlight.material.set_shader_parameter("active", true)
		var get_active:bool = select_highlight.material.get_shader_parameter("active")
		select_highlight.material.set_shader_parameter("active", !get_active)

func set_label(text:String,color:Color)->void:
	label.text=text
	label.add_theme_font_size_override("font_size",30)
	label.add_theme_color_override("font_color",color)


func on_click(): click_piece_signal.emit(self)
